package com.google.code.test.stock;

import org.junit.runner.RunWith;

import com.google.code.Bunit;
import com.google.code.Context;
import com.google.code.Given;
import com.google.code.Then;
import com.google.code.When;

@Context("stock-beans.xml")
@RunWith(Bunit.class)
public class ReplaceItemScenario {

    @Given("a customer who bought a blue garment")
    private Customer customer;

    @Given("two blue garments and three black garments in stock")
    private Stock stock;

    @When("the customer returns the garment for a replacement in black")
    public void replace() {

        Product to = stock.getProductByName("black garment");
        Product from = customer.getProducts().get(0);

        stock.replace(customer, stock, from, to);
    }

    @Then("the stock should have three blue garments and two black garments")
    public boolean ensureThreeBlueGarmetsInStock() {

        return stock.countProductsByName("blue garment") == 3 && stock.countProductsByName("black garment") == 2;
    }

    @Then("the customer should have the black garment")
    public boolean ensureCustomerWithBlackGarment() {

        return customer.getProducts().size() == 1 && customer.getProducts().get(0).getName().equals("black garment");
    }
}
